Skip to content

feat(context): Add contexts subclasses feature#114

Merged
CCXLV merged 31 commits into
mainfrom
feat-contexts
Feb 26, 2026
Merged

feat(context): Add contexts subclasses feature#114
CCXLV merged 31 commits into
mainfrom
feat-contexts

Conversation

@CCXLV

@CCXLV CCXLV commented Feb 20, 2026

Copy link
Copy Markdown
Owner

This PR adds a Context class to implement Dependency Injection for worker tasks.

Key Changes

  • task_with_context: A new decorator that automatically injects the context as the first argument. Developers no longer need to pass the context manually when calling the task function.

  • thread_storage: Uses threading.local within the Context class to store long-lived resources like database engines, ensuring thread isolation.

  • metadata: Provides access to task-specific execution data such as task_id, retry_count, max_retries, and enqueued_at.

Example

@fluxqueue.task_with_context()
def my_task(ctx: Context, param: str):
    print(ctx.metadata.task_id)
   
# ctx is injected; only param is passed by the caller 
my_task("Hello")

@CCXLV CCXLV marked this pull request as draft February 20, 2026 13:10
@CCXLV CCXLV marked this pull request as ready for review February 23, 2026 20:50
@CCXLV CCXLV marked this pull request as draft February 23, 2026 21:02
@CCXLV CCXLV marked this pull request as ready for review February 26, 2026 18:51
@CCXLV CCXLV merged commit 8d13fc6 into main Feb 26, 2026
14 checks passed
@CCXLV CCXLV deleted the feat-contexts branch February 26, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant